package com.tengju.bff.interfaces.manage.club.assembler;

import com.google.common.collect.Lists;
import com.tengju.bff.interfaces.manage.club.vo.PageZoneInfoVO;
import com.tengju.bff.interfaces.manage.club.vo.ZoneInfoVO;
import com.tengju.user.application.archives.dto.PageQueryDTO;
import com.tengju.user.domain.model.club.Zone;
import org.springframework.util.CollectionUtils;

import java.time.format.DateTimeFormatter;
import java.util.List;

public class ZoneAssembler {

    public static PageZoneInfoVO ModelToVO(List<Zone> zoneList, PageQueryDTO pageQueryDTO,Integer total) {

        List<ZoneInfoVO> zoneInfoVOList = Lists.newArrayList();
        PageZoneInfoVO pageZoneInfoVO = new PageZoneInfoVO();
        pageZoneInfoVO.setPageIndex(pageQueryDTO.getPageIndex());
        pageZoneInfoVO.setPageSize(pageQueryDTO.getPageSize());
        pageZoneInfoVO.setTotal(total);

        if (CollectionUtils.isEmpty(zoneList)) {
            return pageZoneInfoVO;
        }

        for (Zone zone : zoneList) {
            ZoneInfoVO zoneInfoVO = new ZoneInfoVO();
            zoneInfoVO.setName(zone.getName());
            zoneInfoVO.setHeadImgUrl(zone.getHeadImg());
            zoneInfoVO.setZoneId(zone.getZoneId().getValue());
            zoneInfoVO.setOperatePerson(zone.getUpdateBy());
            zoneInfoVO.setOperateTime(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(zone.getUpdateTime()));
            zoneInfoVOList.add(zoneInfoVO);
        }
        pageZoneInfoVO.setZoneInfoVOList(zoneInfoVOList);

        return pageZoneInfoVO;


    }

}
